class Solution {
public:
    int dx[4] = {0, 0, -1, 1};
    int dy[4] = {1, -1, 0, 0};
    void numIslands(vector<vector<char>>& grid, vector<vector<bool>>& isexit,int x, int y) 
    {
        isexit[x][y] = true;
        for (int i = 0; i < 4; i++) 
        {
            int newx = x + dx[i];
            int newy = y + dy[i];
            if (newx >= 0 && newx < grid.size() && newy >= 0 &&
                newy < grid[0].size()&&!isexit[newx][newy]&&grid[newx][newy] == '1') {
                numIslands(grid, isexit, newx, newy);
            }
        }
    }//这个函数的目的就是从x，y位置开始网四周进行衍生将所有的陆地标记下来
    int numIslands(vector<vector<char>>& grid) {
        int ret = 0;
        // 题目解法为：DFS，使用一个数组来标记已经访问过的节点，对于是陆地的数字使用标记数组进行标记即可
        vector<vector<bool>> isexit(grid.size(), vector<bool>(grid[0].size(),false));
        for (int i = 0; i < grid.size(); i++) {
            for (int j = 0; j < grid[i].size(); j++) {
                if (!isexit[i][j] && grid[i][j] == '1')
                {
                    ret++;
                    numIslands(grid, isexit, i, j);
                }
            }
        }
        return ret;
    }
};